package gm;

import io.ClientSession;
import platform.Platform;
import player.Player;
import protomsg.Gm.GMMsg;

public class gmStringPrase {

	public static  boolean prase(String content,Player player)
	{
		content = content.toLowerCase();
		String head = "/gm";

		if(content.indexOf(head) == -1) return false;

		String splitChar = " ";
		String[] lst = content.split(splitChar);
		
		int len = lst.length;
		if(len > 1){
			
			String gmStr;
			String propId = "";
			int propNum = 0;
			int silver = 0;
			GMMsg.Builder build = GMMsg.newBuilder();
			String mid = String.valueOf(player.getPlayerInfo().getPlayerID());
			
			gmStr = lst[1];

			if(gmStr.compareTo("additem") == 0 && len >= 4){
				
				propId = lst[2];
				propNum = Integer.parseInt(lst[3]);
				
				try{
					
					ClientSession session = player.getSession();
					
					build.setType(protomsg.Gm.GMType.GMSendPack);
					build.setItemId(Integer.parseInt(propId));
					build.setItemNum(propNum);
					
					build.setUserId(mid);
					GMMsg msg = build.build();
					
					Platform.getServiceManager().getDbService().schedule(new gmGameLoadCall(msg, session));
				}
				catch(Exception e){
					
				}
				
				return true;
			}
			else if(gmStr.compareTo("addsilver") == 0 && len >= 3){
				
				silver = Integer.parseInt(lst[2]);
				build.setType(protomsg.Gm.GMType.AddMoney);
				build.setUserId(mid);
				build.setSilver(silver);
				
				GMMsg msg = build.build();
				ClientSession session = player.getSession();
				Platform.getServiceManager().getDbService().schedule(new gmGameLoadCall(msg, session));
			}
		}

		return false;
	}
}
